import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import {getUserInfo} from '@/apis/login'
export const useUserStore = defineStore('user', () => {
    const user = ref({})
    const getUser = async ({account,password})=>{
        const res = await getUserInfo({account,password})
        user.value = res.data.result
        localStorage.setItem('XtxUser',JSON.stringify(user.value))
    }
    const initUser = ()=>{
        const userData = localStorage.getItem('XtxUser')
        if(userData){
            user.value = JSON.parse(userData)
        }
    }
    const clearUser = ()=>{
        user.value = {}
        localStorage.removeItem('XtxUser')
    }
    return {
        user,
        getUser,
        initUser,
        clearUser
    }
})
